package sopt.dev.util;

import sopt.dev.data.CityAdatper;
import sopt.dev.data.CityVO;
import sopt.dev.data.GagebuDataModel;
import sopt.dev.data.ItemVO;
import sopt.dev.db.DBHelper;
import android.widget.AbsListView;
import android.widget.ListView;
import de.timroes.swipetodismiss.SwipeDismissList;
import de.timroes.swipetodismiss.SwipeDismissList.UndoMode;

public class SwipeListCreator {
	
	static CityVO<ItemVO> deletedItem;

	public static void makeListToSwipeMode(final CityAdatper adapter, ListView list) {
		// swipe to delete
		SwipeDismissList.OnDismissCallback callvack = new SwipeDismissList.OnDismissCallback() {
			// Gets called whenever the user deletes an item.
			public SwipeDismissList.Undoable onDismiss(AbsListView listView, final int position) {
				// Get your item from the adapter (mAdapter being an adapter for MyItem objects)
				deletedItem = (CityVO<ItemVO>) adapter.getItem(position);
				// Delete item from adapter
		
				adapter.remove(deletedItem);
				// Return an Undoable implementing every method
				return new SwipeDismissList.Undoable() {

					// Method is called when user undoes this deletion
					public void undo() {
						// Reinsert item to list
						adapter.add(deletedItem, position);
					}

					// Return an undo message for that item
					public String getTitle() {
						return deletedItem.getCityName() + " deleted";
					}

					// Called when user cannot undo the action anymore
					public void discard() {
						GagebuDataModel.getInstance().delCityData(deletedItem);
						// Use this place to e.g. delete the item from database
						//finallyDeleteFromSomeStorage(deletedItem);
					}
				};
			}
		};
		UndoMode mode = UndoMode.SINGLE_UNDO;
		SwipeDismissList swipeList = new SwipeDismissList(list, callvack, mode);

	}
}

